<template>
    <el-dialog
        :visible.sync="isShow"
        :before-close="handleClose"
        width="60%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        class="myDialog"
    >
        <el-tabs v-model="activeTab" @tab-click="handleClick">
            <el-tab-pane
                label="批量修改课程"
                name="course"
                v-if="tabType == 'course'"
            ></el-tab-pane>
            <el-tab-pane
                label="批量修改模板"
                name="module"
                v-if="tabType == 'module'"
            ></el-tab-pane>
            <el-tab-pane label="批量修改内容" name="content"></el-tab-pane>
        </el-tabs>
        <div v-if="activeTab != 'content'">
            <div style="margin:24px 12px;">
                <span>组名称 :</span>
                <el-radio-group v-model="activeRadio">
                    <el-radio
                        :label="item.key"
                        v-for="item in radios"
                        :disabled="!item.status"
                        :key="item.key"
                    >
                        {{ item.label }}
                    </el-radio>
                </el-radio-group>
            </div>

            <el-form
                :model="editCourseForm"
                ref="editCourseForm"
                label-width="90px"
                label-position="left"
                style="margin-left:12px;"
                :rules="rules"
            >
                <el-row v-if="activeRadio == '0'" gutter="40" class="formPadding">
                    <el-row>
                        <el-row gutter="30">
                            <el-col :span="12">
                                <el-form-item label="原课程:" prop="oldCourseCode">
                                    <el-select
                                        v-model="editCourseForm.oldCourseCode"
                                        filterable
                                        remote
                                        placeholder="请输入（支持模糊查询）"
                                        :remote-method="queryOldCourse"
                                        @change="oldCourseChange"
                                        :disabled="courseCode"
                                        style="width: 100%;"
                                        clearable
                                    >
                                        <el-option
                                            v-for="item in oldCourses"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                        <i class="el-icon-search" slot="prefix"></i>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row gutter="30">
                            <el-col :span="12">
                                <el-form-item label="新课程:" prop="newCourseCode">
                                    <el-select
                                        v-model="editCourseForm.newCourseCode"
                                        filterable
                                        remote
                                        placeholder="请输入（支持模糊查询）"
                                        :remote-method="queryNewCourse"
                                        @change="newCourseChange"
                                        style="width: 100%;"
                                        clearable
                                    >
                                        <el-option
                                            v-for="item in courses"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                        <i class="el-icon-search" slot="prefix"></i>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-row>

                    <!-- 原课程表格 -->

                    <el-row>
                        <edu-table
                            :total="queryTempletsForm.total"
                            @page-change="handleSizeChange"
                            :data="oldTableCoursesList"
                            :height="tableHeight"
                            tooltip-effect="light"
                            :selection="false"
                            :order="false"
                            border
                        >
                            <el-table-column
                                label="课程编号"
                                align="center"
                                min-width="90"
                                fixed="left"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.courseCode }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="课程名称" min-width="200" align="center">
                                <template slot-scope="props">
                                    <span>{{ props.row.courseName }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="专业" align="center" show-overflow-tooltip min-width="120">
                                <template slot-scope="props">
                                    <span>{{ props.row.majorI18n }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="课程区分" align="center" min-width="80">
                                <template slot-scope="props">
                                    <!-- <span>{{ props.row.modelName }}</span> -->
                                    <span v-if="props.row.weekType == 0">教学周</span>
                                    <span v-if="props.row.weekType == 1">实践周</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="考试/查" align="center" width="80">
                                <template slot-scope="props">
                                    <span v-if="props.row.examMode == 1">考试</span>
                                    <span v-if="props.row.examMode == 2">考查</span>
                                    <!-- <span v-if="props.row.examMode === 3">其他</span>
                                    <span v-if="props.row.examMode === 4">未定</span> -->
                                    <!-- <el-select
                                        v-model="props.row.examModeI18n"
                                        size="mini"
                                    >
                                        <el-option
                                            v-for="item in options.types"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        />
                                    </el-select> -->
                                </template>
                            </el-table-column>
                            <el-table-column min-width="200" align="center" label="学分" width="80">
                                <template slot-scope="props">
                                    <span>{{ props.row.credts }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column
                                label="总学/周数"
                                min-width="200"
                                align="center"
                                width="90"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.period }}/{{ props.row.weeks }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="是否必修" width="80">
                                <template slot-scope="props">
                                    <span v-if="props.row.compulsory === '1'">是</span>
                                    <span v-if="props.row.compulsory === '0'">否</span>
                                    <!-- <el-select disabled v-model="props.row.compulsory">
                                        <el-option
                                            key="1"
                                            label="是"
                                            value="1">
                                        </el-option>
                                        <el-option
                                            key="0"
                                            label="否"
                                            value="0">
                                        </el-option>
                                    </el-select> -->
                                </template>
                            </el-table-column>
                            <el-table-column label="上机时间" align="center" width="100">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.computeTime"
                                        disabled
                                        size="mini"
                                        type="text"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="实验时数" align="center" width="80">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.experimentTime"
                                        size="mini"
                                        disabled
                                        type="text"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="各学期周学时分配/周数分配" align="center">
                                <!-- <el-table-column
                                    :label="val"
                                    align="center"
                                    width="90"
                                    v-for="(val, idx) in semesterSorts"
                                    :key="'semester' + (idx + 1)"
                                >
                                    <template slot-scope="props">
                                        <template>
                                            <el-input
                                                v-model="props.row['semester' + (idx + 1)]"
                                                size="mini"
                                                type="number"
                                                :min="0"
                                                disabled
                                                v-if="props.row.weekType == 0"
                                            />
                                            <el-select v-model="props.row['semester' + (idx + 1)]"
                                                v-if="props.row.weekType == 1"
                                                disabled
                                                size="mini">
                                                    <el-option
                                                        key="999"
                                                        label="暑期"
                                                        value="999"
                                                    />
                                            </el-select>
                                        </template>
                                    </template>
                                </el-table-column> -->
                                <el-table-column align="center"  :label="schooolTermItem.label" v-for='(schooolTermItem, k) in semesterListMap' :key='k'>
                                    <template slot-scope="props">
                                        <div v-if='!props.row.edit && props.row.semesters && props.row.semesters.indexOf(k + 1 + "") > -1'>
                                            <span v-if="props.row.weeksType == 0">
                                                {{ props.row.weekHour }}
                                            </span>
                                            <span v-else>
                                                暑期
                                            </span>
                                        </div>
                                    </template>
                                </el-table-column>
                            </el-table-column>
                            <el-table-column label="备注" min-width="150" align="center">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.remarks"
                                        disabled
                                        size="mini"
                                        placeholder="请输入备注"
                                        maxlength="50"
                                    />
                                </template>
                            </el-table-column>
                        </edu-table>
                    </el-row>

                    <!-- 新课程表格 -->

                    <el-row style="margin-top: 40px;">
                        <el-table
                            :data="newTableCoursesList"
                            :height="tableHeight"
                            border
                            tooltip-effect="light"
                            :cell-style='cellStyleMethod'
                            @cell-click='cellCLickMethod'
                        >
                            <el-table-column
                                label="课程编号"
                                align="center"
                                min-width="90"
                                fixed="left"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.courseCode }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="课程名称" min-width="200" align="center">
                                <template slot-scope="props">
                                    <span>{{ props.row.courseName }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="课程区分" align="center" min-width="120">
                                <template slot-scope="props">
                                    <el-select v-model="props.row.weekType" 
                                    size="mini">
                                        <el-option
                                            v-for="item in options.weekTypes"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        />
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="考试/查" align="center" width="80">
                                <template slot-scope="props">
                                    <el-select v-model="props.row.examModeI18n" size="mini">
                                        <el-option
                                            v-for="item in options.types"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        />
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column min-width="200" align="center" label="学分" width="80">
                                <template slot-scope="props">
                                    <span>{{ props.row.credts }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column
                                label="总学/周数"
                                min-width="200"
                                align="center"
                                width="90"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.period }}/{{ props.row.weeks }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="是否必修" width="80">
                                <template slot-scope="props">
                                    <el-select v-model="props.row.compulsory">
                                        <el-option key="1" label="是" value="1"></el-option>
                                        <el-option key="0" label="否" value="0"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="上机时间" align="center" width="80">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.computeTime"
                                        size="mini"
                                        type="number"
                                        onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="实验时数" align="center" width="80">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.experimentTime"
                                        size="mini"
                                        type="text"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="各学期周学时分配/周数分配" align="center">
                                <!-- <el-table-column
                                    :label="val"
                                    align="center"
                                    width="90"
                                    v-for="(val, idx) in semesterSorts"
                                    :key="'semester' + (idx + 1)"
                                >
                                    <template slot-scope="props">
                                        <template>
                                            <el-input
                                                v-model="props.row['semester' + (idx + 1)]"
                                                size="mini"
                                                type="text"
                                                :min="0"
                                                v-if="props.row.weekType == 0"
                                            />
                                            <el-select v-model="props.row['semester' + (idx + 1)]"
                                            v-if="props.row.weekType == 1"
                                            size="mini">
                                                <el-option
                                                    key="999"
                                                    label="暑期"
                                                    value="999"
                                                />
                                            </el-select>
                                        </template>
                                    </template>
                                </el-table-column> -->
                                <el-table-column align="center"  :label="schooolTermItem.label" v-for='(schooolTermItem, k) in semesterListMap' :key='k'>
                                    <template slot-scope="props">
                                        <div v-if='!props.row.edit && props.row.semesters && props.row.semesters.indexOf(k + 1 + "") > -1'>
                                            <span v-if="props.row.weeksType == 0">
                                                {{ props.row.weekHour }}
                                            </span>
                                            <span v-else>
                                                暑期
                                            </span>
                                        </div>
                                    </template>
                                </el-table-column>
                            </el-table-column>
                            <el-table-column label="备注" min-width="150" align="center">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.remarks"
                                        size="mini"
                                        placeholder="请输入备注"
                                        maxlength="50"
                                    />
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-row>
                </el-row>

                <el-row v-if="activeRadio == '1'" gutter="40" class="formPadding">
                    <el-row gutter="40" v-if="editModle">
                        <el-col span="22">
                            <h4 class="red" style="margin-bottom:15px">提示：不是一个模版的方案不能批量新增</h4>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="新增课程:" prop="newAddCourseCode">
                                    <el-select
                                        v-model="editCourseForm.newAddCourseCode"
                                        filterable
                                        remote
                                        placeholder="请输入关键词"
                                        :remote-method="queryNewCourse"
                                        @change="newlyAddedChange"
                                        style="width: 100%;"
                                        clearable
                                        :disabled="editModle"
                                    >
                                        <el-option
                                            v-for="item in courses"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        ></el-option>
                                        <i class="el-icon-search" slot="prefix"></i>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="课程子类别:" prop="labelId">
                                    <el-select
                                        v-model="editCourseForm.labelId"
                                        style="width: 100%;"
                                        clearable
                                        :disabled="editModle"
                                    >
                                        <el-option
                                            v-for="item in courseCategories"
                                            @change="labelIdCom"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-row>
                    <!-- 新增课程表格 -->
                    <el-row>
                        <el-table
                            :data="newlyAddedCoursesList"
                            :height="tableHeight"
                            border
                            tooltip-effect="light"
                            :cell-style='cellStyleMethod'
                            @cell-click='cellCLickMethod'
                        >
                            <el-table-column
                                label="课程编号"
                                align="center"
                                min-width="90"
                                fixed="left"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.courseCode }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="课程名称" min-width="200" align="center">
                                <template slot-scope="props">
                                    <span>{{ props.row.courseName }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="课程区分" align="center" min-width="90">
                                <template slot-scope="props">
                                    <el-select v-model="props.row.weekType" 
                                    @change="selelted(props.row)"
                                    size="mini">
                                        <el-option
                                            v-for="item in options.weekTypes"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        />
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="考试/查" align="center" width="100">
                                <template slot-scope="props">
                                    <el-select v-model="props.row.examMode" size="mini">
                                        <el-option
                                            v-for="item in options.types"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value"
                                        />
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column min-width="200" align="center" label="学分" width="90">
                                <template slot-scope="props">
                                    <span>{{ props.row.credits }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column
                                label="总学/周数"
                                min-width="200"
                                align="center"
                                width="90"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.period }}/{{ props.row.weeks }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="是否必修" width="100">
                                <template slot-scope="props">
                                    <el-select v-model="props.row.compulsory">
                                        <el-option key="1" label="是" value="1"></el-option>
                                        <el-option key="0" label="否" value="0"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="上机时间" align="center" width="100">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.computeTime"
                                        size="mini"
                                        type="number"
                                        onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="实验时数" align="center" width="100">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.experimentTime"
                                        size="mini"
                                        type="text"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="各学期周学时分配/周数分配" align="center">
                                <!-- <el-table-column
                                    :label="val"
                                    align="center"
                                    width="90"
                                    v-for="(val, idx) in semesterSorts"
                                    :key="'semester' + (idx + 1)"
                                >
                                    <template slot-scope="props">
                                        <template>
                                            <el-input
                                                v-model="props.row['semester' + (idx + 1)]"
                                                size="mini"
                                                type="text"
                                                :min="0"
                                                v-if="props.row.weekType == 0"
                                            />
                                            <el-select v-model="props.row['semester' + (idx + 1)]"
                                            v-if="props.row.weekType == 1"
                                            size="mini">
                                                <el-option
                                                    key="999"
                                                    label="暑期"
                                                    value="999"
                                                />
                                            </el-select>
                                        </template>
                                    </template>
                                </el-table-column> -->
                                <el-table-column align="center"  :label="schooolTermItem.label" v-for='(schooolTermItem, k) in semesterListMap' :key='k'>
                                    <template slot-scope="props">
                                        <div v-if='!props.row.edit && props.row.semesters && props.row.semesters.indexOf(k + 1 + "") > -1'>
                                            <span v-if="props.row.weeksType == 0">
                                                {{ props.row.weekHour }}
                                            </span>
                                            <span v-else>
                                                暑期
                                            </span>
                                        </div>
                                    </template>
                                </el-table-column>
                            </el-table-column>
                            <el-table-column label="备注" min-width="150" align="center">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.remarks"
                                        size="mini"
                                        placeholder="请输入备注"
                                        maxlength="50"
                                    />
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-row>
                </el-row>
                <el-row v-if="activeRadio == '2'">
                    <el-col span="12">
                        <el-form-item label="删除课程:" prop="deleteCourseCode">
                            <el-select
                                v-model="editCourseForm.deleteCourseCode"
                                filterable
                                remote
                                placeholder="请输入关键词"
                                :remote-method="queryOldCourse"
                                :disabled="courseCode"
                                style="width: 100%;"
                                clearable
                            >
                                <el-option
                                    v-for="item in oldCourses"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                                <i class="el-icon-search" slot="prefix"></i>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="activeRadio == '3'">
                    <el-row>
                        <el-col span="12">
                            <el-form-item label="查找课程:" prop="searchCourseCode">
                                <el-select
                                    v-model="editCourseForm.searchCourseCode"
                                    filterable
                                    remote
                                    placeholder="请输入（支持模糊查询)"
                                    :remote-method="findSchemeCourse"
                                    @change="findSchemeCourseEdit"
                                    style="width: 100%;"
                                    clearable
                                    :disabled="courseCode"
                                >
                                    <el-option
                                        v-for="item in courses"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                    <i class="el-icon-search" slot="prefix"></i>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <edu-table
                            :total="queryTempletsForm1.total"
                            @current-change="handleCurrentChange1"
                            :data="courseTables"
                            :height="tableHeight"
                            tooltip-effect="light"
                            :selection="false"
                            :order="false"
                            border
                        >
                            <el-table-column
                                label="课程编号"
                                align="center"
                                min-width="90"
                                fixed="left"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.courseCode }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column min-width="200" align="center" label="课程名称">
                                <template slot-scope="props">
                                    <span>{{ props.row.courseName }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column min-width="200" align="center" label="专业">
                                <template slot-scope="props">
                                    <span>{{ props.row.majorI18n }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="课程区分" align="center" min-width="90">
                                <template slot-scope="props">
                                    <span v-if="props.row.weekType == 0">教学周</span>
                                    <span v-if="props.row.weekType == 1">实践周</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="考试/查" align="center" width="100">
                                <template slot-scope="props">
                                    <span>{{ props.row.examModeI18n }}</span>
                                    <!-- <span v-if="props.row.examMode === 3">其他</span>
                                    <span v-if="props.row.examMode === 4">未定</span> -->
                                </template>
                            </el-table-column>
                            <el-table-column min-width="200" align="center" label="学分" width="90">
                                <template slot-scope="props">
                                    <span>{{ props.row.credts }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column
                                label="总学/周数"
                                min-width="200"
                                align="center"
                                width="90"
                            >
                                <template slot-scope="props">
                                    <span>{{ props.row.period }}/{{ props.row.weeks }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="是否必修" width="100">
                                <template slot-scope="props">
                                    <span v-if="props.row.compulsory === '1'">是</span>
                                    <span v-if="props.row.compulsory === '0'">否</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="上机时间" align="center" width="100">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.computeTime"
                                        disabled
                                        size="mini"
                                        type="number"
                                        onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="实验时数" align="center" width="100">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.experimentTime"
                                        disabled
                                        size="mini"
                                        type="text"
                                        :min="0"
                                    />
                                </template>
                            </el-table-column>
                            <el-table-column label="各学期周学时分配/周数分配" align="center">
                                <!-- <el-table-column
                                    :label="val"
                                    align="center"
                                    width="90"
                                    v-for="(val, idx) in semesterSorts"
                                    :key="'semester' + (idx + 1)"
                                >
                                    <template slot-scope="props">
                                        <template>
                                            <el-input
                                                v-model="props.row['semester' + (idx + 1)]"
                                                size="mini"
                                                type="text"
                                                :min="0"
                                                disabled
                                                v-if="props.row.weekType == 0"
                                            />
                                            <el-select v-model="props.row['semester' + (idx + 1)]"
                                            v-if="props.row.weekType == 1"
                                            disabled
                                            size="mini">
                                                <el-option
                                                    key="999"
                                                    label="暑期"
                                                    value="999"
                                                />
                                            </el-select>
                                        </template>
                                    </template>
                                </el-table-column> -->
                                <el-table-column align="center"  :label="schooolTermItem.label" v-for='(schooolTermItem, k) in semesterListMap' :key='k'>
                                    <template slot-scope="props">
                                        <div v-if='props.row.semesters && props.row.semesters.indexOf(k + 1 + "") > -1'>
                                            <span v-if="props.row.weekType == 0">
                                                {{ props.row.weekHour }}
                                            </span>
                                            <span v-else>
                                                暑期
                                            </span>
                                        </div>
                                    </template>
                                </el-table-column>
                            </el-table-column>
                            <el-table-column label="备注" min-width="150" align="center">
                                <template slot-scope="props">
                                    <el-input
                                        v-model="props.row.remark"
                                        disabled
                                        size="mini"
                                        placeholder="请输入备注"
                                        maxlength="50"
                                    />
                                </template>
                            </el-table-column>
                        </edu-table>
                        <el-row style="margin-top: 40px;">
                            <el-table
                                :data="courseSubmitTables"
                                :height="tableHeight"
                                border
                                tooltip-effect="light"
                                :cell-style='cellStyleMethod'
                                @cell-click='cellCLickMethod'
                            >
                                <el-table-column
                                    label="课程编号"
                                    align="center"
                                    min-width="90"
                                    fixed="left"
                                >
                                    <template slot-scope="props">
                                        <span>{{ props.row.courseCode }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="课程名称" min-width="200" align="center">
                                    <template slot-scope="props">
                                        <span>{{ props.row.courseName }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="课程区分" align="center" min-width="90">
                                    <template slot-scope="props">
                                        <span v-if="props.row.weekType == 0">教学周</span>
                                        <span v-if="props.row.weekType == 1">实践周</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="考试/查" align="center" width="100">
                                    <template slot-scope="props">
                                        <el-select v-model="props.row.examMode" size="mini">
                                            <el-option
                                                v-for="item in options.types"
                                                :key="item.value"
                                                :label="item.label"
                                                :value="item.value"
                                            />
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    min-width="200"
                                    align="center"
                                    label="学分"
                                    width="90"
                                >
                                    <template slot-scope="props">
                                        <span>{{ props.row.credts }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="总学/周数"
                                    min-width="200"
                                    align="center"
                                    width="90"
                                >
                                    <template slot-scope="props">
                                        <span>{{ props.row.period }}/{{ props.row.weeks }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="是否必修" width="100">
                                    <template slot-scope="props">
                                        <el-select v-model="props.row.compulsory">
                                            <el-option key="1" label="是" value="1"></el-option>
                                            <el-option key="0" label="否" value="0"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column label="上机时间" align="center" width="100">
                                    <template slot-scope="props">
                                        <!-- <el-input
                                            v-model="props.row.computeTime"
                                            size="mini"
                                            type="text"
                                            :min="0"
                                        /> -->
                                        <el-input
                                            v-model="props.row.computeTime"
                                            size="mini"
                                            type="number"
                                            onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                                            :min="0"
                                        />
                                    </template>
                                </el-table-column>
                                <el-table-column label="实验时数" align="center" width="100">
                                    <template slot-scope="props">
                                        <!-- <el-input
                                            v-model="props.row.experimentTime"
                                            size="mini"
                                            type="text"
                                            :min="0"
                                        /> -->
                                        <el-input
                                            v-model="props.row.experimentTime"
                                            size="mini"
                                            type="number"
                                            onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                                            :min="0"
                                        />
                                    </template>
                                </el-table-column>
                                <el-table-column label="各学期周学时分配/周数分配" align="center">
                                    <!-- <el-table-column
                                        :label="val"
                                        align="center"
                                        width="90"
                                        v-for="(val, idx) in semesterSorts"
                                        :key="'semester' + (idx + 1)"
                                    >
                                        <template slot-scope="props">
                                        <template>
                                            <el-input
                                                v-model="props.row['semester' + (idx + 1)]"
                                                size="mini"
                                                type="text"
                                                :min="0"
                                                onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
                                                v-if="props.row.weekType == 0"
                                            />
                                            <el-select v-model="props.row['semester' + (idx + 1)]"
                                            v-if="props.row.weekType == 1"
                                            size="mini">
                                                <el-option
                                                    key="999"
                                                    label="暑期"
                                                    value="999"
                                                />
                                            </el-select>
                                        </template>
                                    </template>
                                    </el-table-column> -->
                                    <el-table-column align="center"  :label="schooolTermItem.label" v-for='(schooolTermItem, k) in semesterListMap' :key='k'>
                                        <template slot-scope="props">
                                            <div v-if='!props.row.edit && props.row.semesters && props.row.semesters.indexOf(k + 1 + "") > -1'>
                                                <span v-if="props.row.weekType == 0">
                                                    {{ props.row.weekHour }}
                                                </span>
                                                <span v-else>
                                                    暑期
                                                </span>
                                            </div>
                                        </template>
                                    </el-table-column>
                                </el-table-column>
                                <el-table-column label="备注" min-width="150" align="center">
                                    <template slot-scope="props">
                                        <el-input
                                            v-model="props.row.remark"
                                            size="mini"
                                            placeholder="请输入备注"
                                            maxlength="50"
                                        />
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-row>
                    </el-row>
                </el-row>
                <el-form-item label="是否同步个人计划:" label-width="150px">
                    <template>
                        <el-radio-group v-model="singleElection">
                            <el-radio :label="1">是</el-radio>
                            <el-radio :label="0">否</el-radio>
                        </el-radio-group>
                    </template>
                </el-form-item>
            </el-form>
        </div>
        <div v-if="activeTab == 'content'">
            <el-row gutter="40" v-if="editModle">
                <el-col span="22">
                    <h4 class="red">提示：不是一个模版的方案不能编辑章节样例</h4>
                </el-col>
            </el-row>
            <el-form
                :model="editContentForm"
                ref="editContentForm"
                label-width="80px"
                label-position="left"
                style="margin:24px 0 0 12px;"
                :rules="rules1"
            >
                <el-row gutter="40">
                    <el-col span="10">
                        <el-form-item label="选择章节:" prop="chapterId">
                            <el-select
                                v-model="editContentForm.chapterId"
                                style="width: 100%;"
                                clearable
                                :disabled="editModle"
                            >
                                <el-option
                                    v-for="item in chapters"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col span="10">
                        <el-form-item label="中英文:">
                            <el-select
                                v-model="editContentForm.language"
                                style="width: 100%;"
                                clearable
                            >
                                <el-option
                                    v-for="item in languages"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col style="margin-bottom:16px;">
                        <el-radio-group v-model="editContentForm.contentType">
                            <el-radio :label="item.key" v-for="item in positions" :key="item.key">
                                {{ item.label }}
                            </el-radio>
                        </el-radio-group>
                    </el-col>
                    <el-col>
                        <el-form-item label="内容设置:" prop="content">
                            <Tinymce
                                ref="editor"
                                :height="150"
                                v-model="editContentForm.content"
                                :simple="true"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="handleClose">{{ $t('common.btn.cancel') }}</el-button>
            <el-button type="primary" @click="batchEdit">{{ $t('common.btn.confirm') }}</el-button>
        </span>
    </el-dialog>
</template>
<script>
import Tinymce from 'common/src/components/tinymce'
import {
    newCoursePageList, // 新课程的列表
    newCoursePage, // 查询新课程的接口
    batchReplaceCourses,
    findCourseNameOrCodeList,
    findCoursesLabelList,
    batchDelCourses,
    batchAddCourses,
    batchEditContents,
    findSchemeCourse,
    findSchemeCourseTwo,
    getCourses,
    saveCourseInfo,
    findContentList,
    findGradeListByTemplate,
    getSchemeSchoolTermByIds
} from 'common/src/api/culture/bachelor'
import { queryDic } from 'common/src/api/dictionary'
export default {
    components: {
        Tinymce
    },
    props: {
        isShow: { type: Boolean, required: true },
        cultureSchemes: { type: Array, required: false }, //勾选的方案ids
        projId: { type: String, required: false, default: '1' },
        tabType: { type: String, required: false, default: 'course' },
        originData: { type: Array, default: [] },
        editModle: { type: Boolean, required: false },
        templateId: { type: String, required: false,},
    },
    data() {
        return {
            curList: [],
            queryTempletsForm: {
                pageNum_: 1,
                pageSize_: 20,
                total: 0
            }, // 原课程表格分页
            queryTempletsForm1: {
                pageNum_: 1,
                pageSize_: 20,
                total: 0
            }, // 查找课程分页
            singleElection: 1, // 是否同步个人计划
            radios: [
                { label: '批量替换', key: '0', status: true },
                { label: '批量新增', key: '1', status: true },
                { label: '批量删除', key: '2', status: true },
                { label: '批量编辑', key: '3', status: true }
            ],
            positions: [
                { label: '段前插入', key: '1' },
                { label: '段后插入', key: '2' },
                { label: '章节替换', key: '3' }
            ],
            languages: [{ value: 'cn', label: '中文' }, { value: 'en', label: '英文' }],
            activeTab: 'course',
            activeRadio: '0',
            chapters: [],
            tableList: [],
            courseCategories: [], //课程子类别下拉数据
            editCourseForm: {
                labelId: '',
                ids: [], // 给用户展示的将替换的课程里每条数据的id，
                newCourseCode: '',
                oldCourseCode: '',
                searchCourseCode: ''
                // isSynchronousPlan: "0"
            },
            editContentForm: {
                contentType: '1',
                language: 'cn',
                chapterId: '',
                content: ''
            },
            semesterListMap:[],
            schoolTerm: '',
            courses: [],
            oldCourses: [],
            newTableCoursesList: [], //批量替换 新课程表格数据
            oldTableCoursesList: [], //批量替换 原课程表格数据
            newlyAddedCoursesList: [], //批量新增 新增课程表格数据
            courseTables: [], //批量编辑 表格数据
            timeout: null,
            semesterSorts: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十'],
            semesterCodes: { '999': '暑期' },
            currentRow: {}, //当前操作行,新增/编辑/删除时，保存当前操作行
            cultureSchemesList: [],
            courseSubmitTables: [],
            options: {
                types: [{ label: '考试', value: '1' }, { label: '考查', value: '2' }],
                weekTypes: [{ label: '教学周', value: '0' }, { label: '实践周', value: '1' }]
            },
            rules: {
                oldCourseCode: [
                    {
                        required: true,
                        message: '请选择课程',
                        trigger: 'change'
                    }
                ],
                newCourseCode: [
                    {
                        required: true,
                        message: '请选择课程',
                        trigger: 'change'
                    }
                ],
                newAddCourseCode: [
                    {
                        required: true,
                        message: '请选择课程',
                        trigger: 'change'
                    }
                ],
                labelId: [
                    {
                        required: true,
                        message: '请选择课程标签',
                        trigger: 'change'
                    }
                ],
                deleteCourseCode: [
                    {
                        required: true,
                        message: '请选择课程标签',
                        trigger: 'change'
                    }
                ],
                searchCourseCode: [
                    {
                        required: true,
                        message: '请选择课程标签',
                        trigger: 'change'
                    }
                ]
            },
            rules1: {
                chapterId: [
                    {
                        required: true,
                        message: '请选择章节',
                        trigger: 'change'
                    }
                ],
                content: [
                    {
                        required: true,
                        message: '请输入内容',
                        trigger: 'change'
                    }
                ]
            }
        }
    },
    methods: {
        initSemesterListMap() {
            getSchemeSchoolTermByIds(this.cultureSchemes).then(res => {
                if (res.code == 200) {
                    let schoolTerm = 0
                    schoolTerm = res.data.schoolTerm 
                    this.schoolTerm = res.data.schoolTerm 
                    let list = [];
                    let labelArr = ['一',  '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十'];
                    for(let i = 0 ; i< schoolTerm; i++) {
                        list.push({
                            label: labelArr[i],
                            checked: false,
                            key: i + 1
                        })
                    }
                    this.semesterListMap = list;
                }
            })
        },
        cellStyleMethod({row, column, rowIndex, columnIndex}){
            if (column.label && row.semesterListMap) {
                let currentItem = _.find(row.semesterListMap, item => {
                    return item.label === column.label;
                })
                if (currentItem) {
                   if (row.edit) {
                        if (currentItem.checked) {
                            return 'background: #3A7FE8; cursor: pointer';
                        }
                        return "cursor: pointer";
                   }
                }
           }
        },
        cellCLickMethod(row, column) {
            if (!row.edit) return;
            if (column.label && row.semesterListMap) {
                let currentItem = _.find(row.semesterListMap, item => {
                    return item.label === column.label;
                })
                if (currentItem) {
                    currentItem.checked =  !currentItem.checked;
                }
           }
        },
        // 新旧课程目前使用同一接口，应分开
        queryOldCourse(val = this.courseCode) {
            clearTimeout(this.timeout)
            this.timeout = setTimeout(() => {
                findSchemeCourse(
                    this.cultureSchemes,
                    val,
                    this.queryTempletsForm.pageNum_,
                    this.queryTempletsForm.pageSize_
                ).then(res => {
                    if (res.code == 200) {
                        this.oldCourses = _.uniqBy(res.data.list, 'courseCode').map(item => {
                            return {
                                label: `${item.courseName}(${item.courseCode})`,
                                value: item.courseCode
                            }
                        })
                    }
                })
            }, 300)
        },
        // 替换原课程表格数据
        oldCourseChange() {
            if (!this.editCourseForm.oldCourseCode) {
                return
            }
            findSchemeCourseTwo(
                this.cultureSchemes,
                this.editCourseForm.oldCourseCode,
                this.queryTempletsForm.pageNum_,
                this.queryTempletsForm.pageSize_
            ).then(res => {
                if (res.code == 200) {
                    this.queryTempletsForm.total = res.data.total_
                    let arr_ = []
                    arr_ = _.uniqBy(res.data.list, 'courseCode').map(item => {
                        return {
                            courseCode: item.courseCode,
                            courseName: item.courseName,
                            exampleMode: item.exampleMode,
                            computeTime: item.computeTime,
                            experimentTime: item.experimentTime,
                            weekType: item.weekType,
                            weeks: item.weeks,
                            majorI18n: item.majorI18n,
                            semesters:item.semesters?item.semesters.split(","):item.semesters,
                            semesterListMap: _.cloneDeep(this.semesterListMap),
                            // semester1: item.semester1,
                            // semester2: item.semester2,
                            // semester3: item.semester3,
                            // semester4: item.semester4,
                            // semester5: item.semester5,
                            // semester6: item.semester6,
                            // semester7: item.semester7,
                            // semester8: item.semester8,
                            // semester9: item.semester9,
                            // semester10: item.semester10,
                            comment: item.comment,
                            compulsory: item.compulsory,
                            credts: item.credts,
                            credits: item.credits,
                            period: item.period,
                            remarks: item.remark,
                            examMode: item.examMode,
                            directionName: item.directionName,
                            modelName: item.modelName,
                            groupName: item.groupName,
                            examModeI18n: item.examModeI18n,
                            id: item.id
                        }
                    })
                    this.oldTableCoursesList = []
                    this.editCourseForm.ids = []
                    arr_.forEach(item => {
                        this.oldTableCoursesList.push(item)
                        this.editCourseForm.ids.push(item.id)
                    })
                }
            })
        },
        // 替换新课程表格数据
        newCourseChange(val) {
            //this.initOptions();
            if (!this.editCourseForm.newCourseCode) {
                return
            }
            let parms = {
                condition: val,
                pageSize_: 10000,
                pageNum_: 1
            }
            getCourses(parms).then(res => {
                if (res.code == 200) {
                    this.newTableCoursesList = []
                    this.newTableCoursesList = res.data.list.map(item => {
                        return {
                            courseCode: item.code,
                            courseName: item.name,
                            exampleMode: '',
                            computeTime: '',
                            experimentTime: '',
                            weekType: item.weekType,
                            weeks: item.weeks,
                            semesters: [],
                            // semester1: '',
                            // semester2: '',
                            // semester3: '',
                            // semester4: '',
                            // semester5: '',
                            // semester6: '',
                            // semester7: '',
                            // semester8: '',
                            // semester9: '',
                            // semester10: '',
                            semesterListMap: _.cloneDeep(this.semesterListMap),
                            comment: '',
                            compulsory: '',
                            edit:true,
                            credts: item.credits,
                            credits: item.credits,
                            period: item.period,
                            directionName: '',
                            modelName: '',
                            groupName: '',
                            examModeI18n: ''
                        }
                    })
                }
            })
        },
        // 新增课程表格数据
        newlyAddedChange() {
            //this.initOptions();
            console.log(this.editCourseForm.newAddCourseCode)
            if (!this.editCourseForm.newAddCourseCode) {
                return
            }
            let parms = {
                condition: this.editCourseForm.newAddCourseCode,
                pageSize_: 10000,
                pageNum_: 1
            }
            getCourses(parms).then(res => {
                if (res.code == 200) {
                    this.newlyAddedCoursesList = []
                    this.newlyAddedCoursesList =
                        res.data &&
                        res.data.list.map(item => {
                            return {
                                courseCode: item.code,
                                courseName: item.name,
                                weekType: item.weekType ? item.weekType : '0',
                                examMode: item.examMode ? item.examMode : '1',
                                credits: item.credits,
                                period: item.period,
                                weeks: item.weeks,
                                compulsory: item.compulsory ? item.compulsory : '0',
                                computeTime: item.computeTime,
                                experimentTime: item.experimentTime,
                                semesters: [],
                                edit:true,
                                semesterListMap:_.cloneDeep(this.semesterListMap),
                                // semester1: item.semester1,
                                // semester2: item.semester2,
                                // semester3: item.semester3,
                                // semester4: item.semester4,
                                // semester5: item.semester5,
                                // semester6: item.semester6,
                                // semester7: item.semester7,
                                // semester8: item.semester8,
                                // semester9: item.semester9,
                                // semester10: item.semester10,
                                remarks: item.remarks
                            }
                        })
                }
            })
        },
        //切换课时
        selelted(row){
            // if(this.weekData == ""){
            //     this.weekData = _.cloneDeep(row)
            // }
            // row.semester1 = ""
            // row.semester2 = ""
            // row.semester3 = ""
            // row.semester4 = ""
            // row.semester5 = ""
            // row.semester6 = ""
            // row.semester7 = ""
            // row.semester8 = ""
            // row.semester9 = ""
            // row.semester10 = ""
            row.semesters = []
            row.edit = true
        },
        // 新课程下拉数据
        queryNewCourse(val) {
            let parms = {
                condition: val,
                pageSize_: 20,
                pageNum_: 1
            }
            getCourses(parms).then(res => {
                if (res.code == 200) {
                    this.courses = res.data.list.map(item => {
                        return {
                            label: 'en' === this.$store.getters.language ? `${item.nameEn}(${item.code})` : `${item.name}(${item.code})`,
                            value: item.code
                        }
                    })
                }
            })
        },
        init() {
            if (this.activeTab == 'content') {
                if (this.$refs['editContentForm']) this.$refs['editContentForm'].clearValidate()
                this.loadChapter()
            }
            if (this.activeTab == 'course' || this.activeTab == 'module') {
                if (this.cultureSchemes) {
                    if (this.$refs['editCourseForm']) {
                        this.$refs['editCourseForm'].clearValidate()
                        this.editCourseForm.newCourseCode = ''
                        this.editCourseForm.oldCourseCode = ''
                        this.editCourseForm.searchCourseCode = ''
                        this.editCourseForm.labelId = ''
                        this.coursesNew = []
                        this.courses = []
                        this.courseTables = []
                    }
                    this.queryOldCourse()
                }
            }
            // if (this.activeTab == "course") {
            //     if (this.$refs["editCourseForm"])
            //         this.$refs["editCourseForm"].resetFields();
            //         this.loadChapter();
            // } else {
            //     if (this.$refs["editContentForm"])
            //         this.$refs["editContentForm"].resetFields();
            // }
        },
        // 课程子类别下拉数据
        loadCourseCategory() {
            // findCoursesLabelList(this.cultureSchemesList).then(res => {
            //     if (res.code == 200) {
            //         this.courseCategories = res.data.map(ele => {
            //             return { label: ele.namecn, value: ele.labid }
            //         })
            //     }
            // })
            if(!this.editModle){
                findGradeListByTemplate(this.templateId).then(res => {
                    if (res.code == 200) {
                        this.courseCategories = res.data.map(ele => {
                            return { label: ele.label, value: ele.id }
                        })
                    }
                })
            }
        },
        // 课程子类别选择
        labelIdCom(val) {
            findSchemeCourse(
                this.cultureSchemes,
                val,
                this.queryTempletsForm.pageNum_,
                this.queryTempletsForm.pageSize_
            ).then(res => {
                console.log('res:', res)
            })
        },
        initOptions() {
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['X_KSLX']
            }
            queryDic(data).then(res => {
                if (res.code == 200) {
                    this.loadOptions('types', res.data.X_KSLX)
                }
            })
        },
        loadOptions(optionKey, dataObj) {
            for (let key in dataObj) {
                this.options[optionKey].push({
                    value: key,
                    label: dataObj[key]
                })
            }
        },
        loadChapter() {
            findContentList(this.cultureSchemes).then(res => {
                if (res.code == 200) {
                    this.chapters = res.data.map(ele => {
                        return { label: ele.name, value: ele.id, labelEn: ele.nameEn }
                    })
                }
            })
        },
        batchEdit() {
            if (this.activeTab == 'course' || this.activeTab == 'module') this.bitchEditCourse()
            else this.bitchEditContent()
        },
        bitchEditCourse() {
            this.$refs['editCourseForm'].validate(valid => {
                if (valid) {
                    Object.assign(this.editCourseForm, this.getCommonParam())
                    if (this.activeRadio == '0') this.batchReplaceCourse()
                    else if (this.activeRadio == '1') this.batchAddCourse()
                    else if (this.activeRadio == '2') this.batchDeleteCourse()
                    else if (this.activeRadio == '3') this.saveCourseInfo()
                }
            })
        },
        handleSizeChange(data) {
            this.queryTempletsForm.pageSize_ = data.pageSize
            this.queryTempletsForm.pageNum_ = data.pageNum
            this.oldCourseChange()
        },
        handleSizeChange1(val) {
            this.queryTempletsForm1.pageSize_ = val
            this.oldCourseChange()
        },
        handleCurrentChange1(val) {
            this.queryTempletsForm1.pageSize_ = data.pageSize
            this.queryTempletsForm1.pageNum_ = data.pageNum
            this.oldCourseChange()
        },
        getCommonParam() {
            let param = { templateId: this.currentTemplet }
            if (this.cultureSchemes && this.cultureSchemes.length > 0)
                param.cultureSchemeIdList = this.cultureSchemesList
            return param
        },
        // 批量新增提交
        batchAddCourse() {
            this.editCourseForm.tainingIDs = this.editCourseForm.cultureSchemeIdList
            this.editCourseForm.courseCode = this.newlyAddedCoursesList[0].courseCode
            this.editCourseForm.weeksType = this.newlyAddedCoursesList[0].weekType
            this.editCourseForm.examMode = this.newlyAddedCoursesList[0].examMode
            this.editCourseForm.compulsory = this.newlyAddedCoursesList[0].compulsory
            this.editCourseForm.computeTime = this.newlyAddedCoursesList[0].computeTime
            this.editCourseForm.experimentTime = this.newlyAddedCoursesList[0].experimentTime
            let changedSemester = [];
            this.newlyAddedCoursesList[0].semesterListMap.forEach(spec => {
                if (spec.checked) {
                    changedSemester.push(spec.key);
                }
            })
            this.editCourseForm.semesters = changedSemester.join(',');
            // this.editCourseForm.semester1 = this.newlyAddedCoursesList[0].semester1
            // this.editCourseForm.semester2 = this.newlyAddedCoursesList[0].semester2
            // this.editCourseForm.semester3 = this.newlyAddedCoursesList[0].semester3
            // this.editCourseForm.semester4 = this.newlyAddedCoursesList[0].semester4
            // this.editCourseForm.semester5 = this.newlyAddedCoursesList[0].semester5
            // this.editCourseForm.semester6 = this.newlyAddedCoursesList[0].semester6
            // this.editCourseForm.semester7 = this.newlyAddedCoursesList[0].semester7
            // this.editCourseForm.semester8 = this.newlyAddedCoursesList[0].semester8
            // this.editCourseForm.semester9 = this.newlyAddedCoursesList[0].semester9
            // this.editCourseForm.semester10 = this.newlyAddedCoursesList[0].semester10
            this.editCourseForm.remarks = this.newlyAddedCoursesList[0].remarks
            batchAddCourses(this.editCourseForm, this.singleElection).then(res => {
                if (res.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '操作成功!'
                    })
                    this.reset()
                    this.handleClose()
                }
            })
        },
        // 批量替换提交
        batchReplaceCourse() {
            console.log(this.newTableCoursesList[0])
            this.editCourseForm.tainingIDs = this.editCourseForm.cultureSchemeIdList
            this.editCourseForm.code = this.editCourseForm.newCourseCode
            this.editCourseForm.courseCode = this.editCourseForm.oldCourseCode
            this.editCourseForm.weeksType = this.newTableCoursesList[0].weekType
            this.editCourseForm.examMode = this.newTableCoursesList[0].examModeI18n
            this.editCourseForm.credts = this.newTableCoursesList[0].credts
            this.editCourseForm.period = this.newTableCoursesList[0].period
            this.editCourseForm.weeks = this.newTableCoursesList[0].weeks
            this.editCourseForm.compulsory = this.newTableCoursesList[0].compulsory
            this.editCourseForm.computeTime = this.newTableCoursesList[0].computeTime
            this.editCourseForm.experimentTime = this.newTableCoursesList[0].experimentTime
            let changedSemester = [];
            this.newTableCoursesList[0].semesterListMap.forEach(spec => {
                if (spec.checked) {
                    changedSemester.push(spec.key);
                }
            })
            this.editCourseForm.semesters = changedSemester.join(',');
            // this.editCourseForm.semester1 = this.newTableCoursesList[0].semester1
            // this.editCourseForm.semester2 = this.newTableCoursesList[0].semester2
            // this.editCourseForm.semester3 = this.newTableCoursesList[0].semester3
            // this.editCourseForm.semester4 = this.newTableCoursesList[0].semester4
            // this.editCourseForm.semester5 = this.newTableCoursesList[0].semester5
            // this.editCourseForm.semester6 = this.newTableCoursesList[0].semester6
            // this.editCourseForm.semester7 = this.newTableCoursesList[0].semester7
            // this.editCourseForm.semester8 = this.newTableCoursesList[0].semester8
            // this.editCourseForm.semester9 = this.newTableCoursesList[0].semester9
            // this.editCourseForm.semester10 = this.newTableCoursesList[0].semester10
            this.editCourseForm.remarks = this.newTableCoursesList[0].remarks
            console.log(this.editCourseForm)
            batchReplaceCourses(this.editCourseForm, this.singleElection).then(res => {
                if (res.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '操作成功!'
                    })
                    // this.$refs["editCourseForm"].resetFields();
                    this.handleClose()
                    this.reset()
                }
            })
        },
        // 批量删除提交
        batchDeleteCourse() {
            batchDelCourses(this.editCourseForm, this.singleElection).then(res => {
                if (res.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '操作成功!'
                    })
                    this.reset()
                    this.handleClose()
                }
            })
        },
        // 批量编辑提交
        saveCourseInfo() {
            let changedSemester = [];
            this.courseSubmitTables[0].semesterListMap.forEach(spec => {
                if (spec.checked) {
                    changedSemester.push(spec.key);
                }
            })
            this.editCourseForm.semesters = changedSemester.join(',');
            console.log(this.courseSubmitTables[0])
            this.editCourseForm.idList = this.cultureSchemesList
            this.editCourseForm.tainingIDs = this.editCourseForm.cultureSchemeIdList
            this.editCourseForm.courseCode = this.editCourseForm.searchCourseCode
            this.editCourseForm.weeksType = this.courseSubmitTables[0].weeksType
            this.editCourseForm.examMode = this.courseSubmitTables[0].examMode
            this.editCourseForm.credts = this.courseSubmitTables[0].credts
            this.editCourseForm.period = this.courseSubmitTables[0].period
            this.editCourseForm.weeks = this.courseSubmitTables[0].weeks
            this.editCourseForm.compulsory = this.courseSubmitTables[0].compulsory
            this.editCourseForm.computeTime = this.courseSubmitTables[0].computeTime
            this.editCourseForm.experimentTime = this.courseSubmitTables[0].experimentTime
            // this.editCourseForm.semester1 = this.courseSubmitTables[0].semester1
            // this.editCourseForm.semester2 = this.courseSubmitTables[0].semester2
            // this.editCourseForm.semester3 = this.courseSubmitTables[0].semester3
            // this.editCourseForm.semester4 = this.courseSubmitTables[0].semester4
            // this.editCourseForm.semester5 = this.courseSubmitTables[0].semester5
            // this.editCourseForm.semester6 = this.courseSubmitTables[0].semester6
            // this.editCourseForm.semester7 = this.courseSubmitTables[0].semester7
            // this.editCourseForm.semester8 = this.courseSubmitTables[0].semester8
            // this.editCourseForm.semester9 = this.courseSubmitTables[0].semester9
            // this.editCourseForm.semester10 = this.courseSubmitTables[0].semester10
            this.editCourseForm.remarks = this.courseSubmitTables[0].remark
            saveCourseInfo(this.editCourseForm, this.singleElection)
                .then(res => {
                    if (res.code == 200) {
                        this.$message({
                            type: 'success',
                            message: '提交成功!'
                        })
                        this.reset()
                        this.handleClose()
                    }
                })
                .catch(() => {
                    this.$message({
                        type: 'error',
                        message: '提交失败!'
                    })
                })
        },
        // 批量修改内容模块
        bitchEditContent() {
            let _this = this
            this.$refs['editContentForm'].validate(valid => {
                if (valid) {
                    let parms = null
                    let chapter = this.chapters.find(c => c.value == this.editContentForm.chapterId)
                    if (this.editContentForm.language == 'cn') {
                        parms = {
                            name: chapter.label,
                            nameEn: '',
                            content: this.editContentForm.content,
                            contentEn: '',
                            cultureIDliSt: this.cultureSchemes,
                            updateType: this.editContentForm.contentType
                        }
                    } else {
                        parms = {
                            name: '',
                            nameEn: chapter.labelEn,
                            content: '',
                            contentEn: this.editContentForm.content,
                            cultureIDliSt: this.cultureSchemes,
                            updateType: (+this.editContentForm.contentType + 3).toString()
                        }
                    }
                    batchEditContents(parms).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                type: 'success',
                                message: '操作成功!'
                            })
                            this.handleClose()
                        }
                    })
                }
            })
        },
        // 查找课程获取下拉数据
        findSchemeCourse(val=this.editCourseForm.searchCourseCode) {
            if (!val) {
                this.courseTables = []
                return
            }
            findSchemeCourse(
                this.cultureSchemes,
                val,
                this.queryTempletsForm1.pageNum_,
                this.queryTempletsForm.pageSize_
            ).then(res => {
                if (res.code == 200) {
                    this.tableList = res.data
                    this.courses = res.data.list.map(item => {
                        return {
                            value: item.courseCode,
                            label: `${item.courseName}(${item.courseCode})`
                        }
                    })
                }
            })
        },
        // 查找课程获取表格数据
        findSchemeCourseEdit() {
            //this.initOptions();
            if (!this.editCourseForm.searchCourseCode) {
                this.courseTables = []
                return
            }

            findSchemeCourseTwo(
                this.cultureSchemes,
                this.editCourseForm.searchCourseCode,
                this.queryTempletsForm1.pageNum_,
                this.queryTempletsForm.pageSize_
            ).then(res => {
                if (res.code == 200) {
                    this.queryTempletsForm1.total = res.data.total_
                    this.courseTables = _.uniqBy(res.data.list, 'courseCode').map(item => {
                        return {
                            courseCode: item.courseCode,
                            courseName: item.courseName,
                            exampleMode: item.exampleMode,
                            computeTime: item.computeTime,
                            experimentTime: item.experimentTime,
                            weekType: item.weekType,
                            weeks: item.weeks,
                            majorI18n: item.majorI18n,
                            semesters:item.semesters?item.semesters.split(","):item.semesters,
                            semesterListMap: _.cloneDeep(this.semesterListMap),
                            // semester1: item.semester1,
                            // semester2: item.semester2,
                            // semester3: item.semester3,
                            // semester4: item.semester4,
                            // semester5: item.semester5,
                            // semester6: item.semester6,
                            // semester7: item.semester7,
                            // semester8: item.semester8,
                            // semester9: item.semester9,
                            // semester10: item.semester10,
                            comment: item.comment,
                            compulsory: item.compulsory,
                            credts: item.credts,
                            credits: item.credits,
                            period: item.period,
                            directionName: item.directionName,
                            modelName: item.modelName,
                            groupName: item.groupName,
                            examMode: item.examMode,
                            examModeI18n: item.examModeI18n,
                            remark: item.remark
                        }
                    })
                    this.courseSubmitTables = []
                    this.courseSubmitTables.push(_.cloneDeep(this.courseTables[0]))
                    if(this.courseSubmitTables[0].semesters.length > 0){
                        let semesters = this.courseSubmitTables[0].semesters
                        semesters.forEach(d =>{
                            this.courseSubmitTables[0].semesterListMap.forEach(f =>{
                                if(d == f.key){
                                    f.checked = true
                                }
                            })
                        })
                    }else{
                        this.courseSubmitTables[0].semesterListMap.forEach(d =>{
                            if(d.checked){
                                d.checked = false
                            }
                        })
                    }
                    this.courseSubmitTables[0].edit = true
                    console.log(this.courseSubmitTables)
                }
            })
        },

        handleClose() {
            this.$emit('change-visible')
        },
        reset() {
            this.editCourseForm = {
                newCourseCode: '',
                oldCourseCode: '',
                newAddCourseCode: '',
                searchCourseCode: '',
                labelId: '',
                chapterId: '',
                content: ''
            }
            this.editContentForm.newAddCourseCode = ''
            this.editContentForm.searchCourseCode = ''
            this.editContentForm.deleteCourseCode = ''
            this.editContentForm.chapterId = ''
            this.editContentForm.content = ''
            ;(this.newTableCoursesList = []),
                (this.oldTableCoursesList = []),
                (this.newlyAddedCoursesList = []),
                (this.courseTables = []),
                (this.courseSubmitTables = []),
                // this.singleElection = '',
                (this.singleElection = 1),
                (this.courses = [])
        }
    },
    watch: {
        isShow: function(_n, _o) {
            this.editCourseForm.oldCourseCode = this.courseName
            this.cultureSchemesList = _.cloneDeep(this.cultureSchemes)
            this.cultureSchemes = this.cultureSchemes.toString()
            // this.editCourseForm = {
            //     newCourseCode: '',
            //     oldCourseCode: '',
            //     newAddCourseCode: '',
            //     searchCourseCode: '',
            //     labelId: '',
            //     chapterId: '',
            //     content: ''
            // };
            ;(this.newTableCoursesList = []),
                (this.oldTableCoursesList = []),
                (this.newlyAddedCoursesList = []),
                (this.courseTables = []),
                // this.singleElection = '',
                (this.singleElection = 1),
                (this.courseSubmitTables = []),
                (this.coursesNew = [])
            this.courses = []
            if (_n) {
                this.activeRadio = '0'
                this.editCourseForm.oldCourseCode = this.courseCode
                this.activeTab = this.tabType
                this.init()
                this.initSemesterListMap()
                if (this.courseCode) this.radios.splice(1, 1)
            }
        },
        activeTab: function(_n, _o) {
            if (this.$refs['editCourseForm']) {
                this.$refs['editCourseForm'].clearValidate()
                if (!this.courseCode) {
                    this.editCourseForm = {
                        newCourseCode: '',
                        oldCourseCode: '',
                        newAddCourseCode: '',
                        searchCourseCode: '',
                        labelId: '',
                        chapterId: '',
                        content: ''
                    }
                }
                ;(this.newTableCoursesList = []),
                    (this.oldTableCoursesList = []),
                    (this.newlyAddedCoursesList = []),
                    (this.courseTables = []),
                    // this.singleElection = '',
                    (this.singleElection = 1),
                    (this.courseSubmitTables = []),
                    (this.coursesNew = [])
                this.courses = []
                this.coursesOld = []
            }
            if (this.$refs['editContentForm']) {
                this.$refs['editContentForm'].clearValidate()
                this.editContentForm.chapterId = ''
                this.editContentForm.content = ''
            }
            this.init()
            this.courses = []
        },
        activeRadio: function(_n, _o) {
            if (!this.courseCode) this.init()
            if(_n == 1){
                this.loadCourseCategory()
            }
            if (this.courseCode && _n == 2) {
                this.editCourseForm.deleteCourseCode = this.courseCode
            }else if(this.courseCode && _n==3){
                this.editCourseForm.searchCourseCode =this.courseCode;
            }
        },
        // 'editCourseForm.searchCourseCode':function(_n, _o) {
        //    if(_n){
        //        this.options.types=[];
        //        this.courseTables=[];

        //        //this.findSchemeCourse();
        //        this.initOptions();
        //    }
        // },
        trainingLevel: function(_n, _o) {
            this.loadCourseCategory()
        },
        'editCourseForm.oldCourseCode': function(_n, _o) {
            if (_n) {
                this.queryOldCourse()
                this.oldCourseChange()
            }
        },
        'editCourseForm.searchCourseCode':function(_n,_o){
            if(_n){
                this.findSchemeCourse();
                this.findSchemeCourseEdit();
            }

        }
    }
}
</script>
<style lang="scss" scoped>
.formPadding {
    padding: 12px;
}
.red{
    color:red;
    margin-left: 12px;
}
</style>

